#!/usr/bin/perl

# $Id: 08_nmap.t 181 2010-07-04 13:39:47Z dolbanavt $
# $Date: 2010-07-04 16:39:52 +0300 (Вск, 04 Июл 2010) $
# $HeadURL: https://robosearch.googlecode.com/svn/branches/reborn/t/08_nmap.t $
# $LastChangedRevision$

use FindBin qw( $RealBin );
use File::Spec::Functions qw( catfile );

BEGIN {
    push @INC, catfile( $RealBin, '..', 'base_lib' );
}

use JIP::ToolSet;
use English qw( -no_match_vars );
use Const::Fast qw( const );
use IPC::Open3::Utils qw( put_cmd_in );
use Test::More 0.88;
use Test::Builder;

# configures behavior and functionality of put_cmd_in(). boolean arguments
const my $ARGS_FOR_OPEN3 => {
    stop_read_on_open3_err => 1,
};

my $test = Test::Builder->new();

{
    put_cmd_in( 'nmap -V', \my $stdout, \my $stderr, $ARGS_FOR_OPEN3 );

    if ( $CHILD_ERROR ) {
        $test->ok( 0, 'nmap not installed' );
        $test->note( 'stderr listing: '. $stderr );
    }
    else {
        $test->ok( 1, 'nmap is recognized as external tool' );

        if ( my ( $version ) = $stdout =~ m{Nmap\sversion\s(\d+\.\d+)}xms ) {
            $test->ok( 1, 'nmap has version: '. $version )
        }
        else {
            $test->ok( 0, 'nmap has no version' )
        }
    }
}

done_testing();
